package lab02.Test24;

import java.util.Calendar;
/**
 * Created by tanfei on 2017/11/1.
 */
public class Test {
    int Day, Month, Year;
    Calendar cal;
    public Test(){};
    public Test( int day, int month, int year){
        cal = Calendar.getInstance();
        cal.set(year, month - 1, day);//范围从0开始
    }
    public void function(Test d) {
        Calendar c = (Calendar) d.cal.clone();
        int days = 0;
        if (cal.after(c)) {
            while (cal.after(c)) {
                days++;
                c.add(Calendar.DATE, 1);
            }
        } else if (cal.before(c)) {
            while (cal.before(c)) {
                days++;
                c.add(Calendar.DATE, -1);
            }
        }
        System.out.println("相差天数为：" + days);
    }

    public static void main(String[] args) {
        Test d1=new Test(11,1,2017);
        Test d2=new Test(1,6,1998);
        d1.function(d2);
    }
}
